package com.example.controller;

import com.example.common.Result;
import com.example.entity.Diagnosis;
import com.example.service.DiagnosisService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 诊断表前端操作接口
 **/
@RestController
@RequestMapping("/diagnosis")
public class DiagnosisController {

    @Autowired
    private DiagnosisService diagnosisService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody Diagnosis diagnosis) {
        diagnosisService.add(diagnosis);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        diagnosisService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        diagnosisService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody Diagnosis diagnosis) {
        diagnosisService.updateById(diagnosis);
        return Result.success();
    }
    /**
     * 修改
     */
    @PutMapping("/updateStatus")
    public Result updateUpdateStatusById(@RequestBody Diagnosis diagnosis) {
        diagnosisService.updateUpdateStatusById(diagnosis);
        return Result.success();
    }


    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Diagnosis diagnosis = diagnosisService.selectById(id);
        return Result.success(diagnosis);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(Diagnosis diagnosis) {
        List<Diagnosis> list = diagnosisService.selectAll(diagnosis);
        return Result.success(list);
    }

    @GetMapping("/selectDiagnosisPendingToAdmin")
    public Result selectDiagnosisPendingToAdmin(Diagnosis diagnosis,
                                            @RequestParam(defaultValue = "1") Integer pageNum,
                                            @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Diagnosis> page = diagnosisService.selectDiagnosisPendingToAdmin(diagnosis, pageNum, pageSize);
        return Result.success(page);
    }


    @GetMapping("/selectDiagnosisPageToUser")
    public Result selectDiagnosisPageToUser(Diagnosis diagnosis,
                                                @RequestParam(defaultValue = "1") Integer pageNum,
                                                @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Diagnosis> page = diagnosisService.selectDiagnosisPageToUser(diagnosis, pageNum, pageSize);
        return Result.success(page);
    }

    @GetMapping("/selectDiagnosisPageToExpert")
    public Result selectDiagnosisPageToExpert(Diagnosis diagnosis,
                                            @RequestParam(defaultValue = "1") Integer pageNum,
                                            @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Diagnosis> page = diagnosisService.selectDiagnosisPageToExpert(diagnosis, pageNum, pageSize);
        return Result.success(page);
    }

    @GetMapping("/selectDiagnosedPageToExpert")
    public Result selectDiagnosedPageToExpert(Diagnosis diagnosis,
                                              @RequestParam(defaultValue = "1") Integer pageNum,
                                              @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Diagnosis> page = diagnosisService.selectDiagnosedPageToExpert(diagnosis, pageNum, pageSize);
        return Result.success(page);
    }

}